package com.tchintech.pay.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.tchintech.pay.R;
import com.tchintech.pay.model.entity.Money;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/8/31 0031.
 */

public class AllMoneyAdapter extends BaseAdapter {
    private Context context;
    private List<Money> list;

    public AllMoneyAdapter(Context context, List<Money> list) {
        this.context = context;
        this.list = list;
    }

    public void setList(List<Money> list) {
        if (list != null) {
            if (!this.list.containsAll(list)) {
                this.list.addAll(list);
            }
        } else {
            this.list = new ArrayList<Money>();
        }
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Money getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View v, ViewGroup parent) {
        Viewholde vh = null;
        if (v == null) {
            vh = new Viewholde();
            v = LayoutInflater.from(context).inflate(R.layout.item_allmoney, null);
            vh.tv_money = (TextView) v.findViewById(R.id.tv_money);
            vh.tv_way = (TextView) v.findViewById(R.id.tv_way);
            v.setTag(vh);
        } else {
            vh = (Viewholde) v.getTag();
        }
        Money money = list.get(position);
        vh.tv_money.setText(money.getMoney());
        vh.tv_way.setText(money.getWay());
        if (money.getWay().equals("余额")) {
            vh.tv_money.setTextColor(ContextCompat.getColor(context, R.color.green));
            vh.tv_way.setTextColor(ContextCompat.getColor(context, R.color.green));
        } else {
            vh.tv_money.setTextColor(ContextCompat.getColor(context, R.color.red));
            vh.tv_way.setTextColor(ContextCompat.getColor(context, R.color.red));
        }

        return v;

    }

    class Viewholde {
        TextView tv_way, tv_money;
    }
}
